<script src="js/jquery/plugins/treeview.js" type="text/javascript"></script>
<script src="js/jquery/plugins/treetable.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="{$theme}css/treeview.css" media="screen"/>

{literal}
<style type="text/css">
	.collapsed { display: none; }
	#tablemain {border-collapse: collapse; border: 0px; margin: 0px; padding: 0px;  }
	#treetable td { font: normal 10pt Arial; padding: 0px 2px 0px 0px; cursor: pointer;}
	.ttimage, .parimg, .preimg { border: none; margin: 0px; padding: 0px; vertical-align: bottom; width: 16px; height: 16px; }
	.parimg {cursor: pointer; }
	.even { background-color: #ff8; }
	.over { background-color: #ccf; }
	.selected { background-color: #ddf; }
</style>
  
<script>
	var map = new Array();
	var collapse = new Array();
</script>
{/literal} 
 
 <table width='100%'>
 	<tr>
 		<td width="600" valign='top'>
 
			<table border='1' class="contentTable" id="tablemain" style='width:600px'>
				<thead>
				<tr class="table_head">
					<th>Name</th>
					<th colspan="6">Actions</th>
				</tr>
				</thead>
				{*<tfoot>
					<tr>
						<th colspan="7">&nbsp;</th>
					</tr>
				</tfoot>*}
				<tbody id="treetable">
				
				{assign var=prev value=0}
				{assign var=collapse_offset value=0}
				{foreach from=$tree item=node key=cid name='tree'}
					
				{if $cid>0}
					{assign var=prev_key value=$cid-1}
					
					{if $tree[$prev_key]->module_level>$node->module_level}
						{assign var=level value=$node->module_level-1}				
						{assign var=prev value=$xxx_$level}	
					{/if}
					
					{if $tree[$prev_key]->module_level<$node->module_level}						
						{assign var=level value=$node->module_level}
						{assign var=prev value=$smarty.foreach.tree.iteration-1}
						{assign var=xxx_$level value=$prev}
					{/if}
				{/if}
				<tr>
					<td width='500'>
						<script>
							map[{$cid}] = {$prev};
							{if $node->module_level==2}
								collapse[{$collapse_offset}] = {$cid+1}
								{assign var=collapse_offset value=$collapse_offset+1}
							{/if}
						</script>
						<strong>{$node->module_name}</strong> {if $node->module_level==2}module{/if}{if $node->module_level==3}controller{/if} {if $node->module_level==4}action{/if}
					</td>
					
					<td {if $node->module_level==1}colspan="6" width='204'{else} width='34'{/if}>
						{if $node->module_level<4}<a href="/admin/modules/addform/module_id/{$node->module_id}"><img src="{$theme}images/icons/add.png" border="0" alt="Add"/></a>{else}&nbsp;{/if}			
					</td>
					{if $node->module_level>1}
					<td width='34'>
						<a href="/admin/modules/editform/module_id/{$node->module_id}"><img src="{$theme}images/icons/next.png" border="0" alt="Edit"/></a>			
					</td>
					<td width='34'>
						<a href="/admin/modules/deletebranch/module_id/{$node->module_id}" onclick="if(!confirm('Are you sure?')) return false;"><img src="{$theme}images/icons/remove.png" border="0" alt="Delete"/></a>
					</td>
					<td width='34'>
						{if $node->previous_id}<a href="/admin/modules/moveup/module_id/{$node->module_id}/nnode_id/{$node->previous_id}"><img src="{$theme}images/icons/up.png" border="0" alt="Up"/></a>{else}&nbsp;{/if}
					</td>
					<td width='34'>
						{if $node->next_id}<a href="/admin/modules/movedown/module_id/{$node->module_id}/nnode_id/{$node->next_id}"><img src="{$theme}images/icons/down.png" border="0" alt="Down"/></a>{else}&nbsp;{/if}
					</td>	
					<td width='34'>
						<a href="/admin/modules/moveform/module_id/{$node->module_id}"><img src="{$theme}images/icons/process.png" border="0" alt="Move"/></a>
					</td>	
					{/if}
				</tr>	
				{/foreach}
				</tbody>
			</table>

		</td>
		<td width='50'>
			&nbsp;
		</td>		
		<td valign='top'>
			<h3>Modules Found Automatically</h3>
			<ul id='sTree'>
			{foreach from=$scanned_modules.module item=s_module key=cid}
				<li><strong>{$s_module.name}</strong> module {if !$s_module.added}<a href='/admin/modules/addnode/module_id/{$root_node_id}/module_name/{$s_module.name}'><img src="{$theme}images/icons/add.png" border="0" alt="Add" width=12 height=12/></a>{/if}
					<ul>
					{foreach from=$s_module.controller item=s_controller}
							<li><strong>{$s_controller.name}</strong> controller {if $s_module.added && !$s_controller.added}<a href='/admin/modules/addnode/module_id/{$s_module.added}/module_name/{$s_controller.name}'><img src="{$theme}images/icons/add.png" border="0" alt="Add" width=12 height=12/></a>{/if}
								<ul>
								{foreach from=$s_controller.action item=s_action}
									<li><strong>{$s_action.name}</strong> action {if $s_module.added && $s_controller.added && !$s_action.added}<a href='/admin/modules/addnode/module_id/{$s_controller.added}/module_name/{$s_action.name}'><img src="{$theme}images/icons/add.png" border="0" alt="Add" width=12 height=12/></a>{/if}</li>
								{/foreach}
								</ul>
							</li>	
					{/foreach}
					</ul>
				</li>
			{/foreach}
			</ul>
		</td>
	</tr>
</table>

{literal}
<script type="text/javascript">
$(function(){
{/literal} 
    var options = {literal}{{/literal}openImg: "{$theme}images/treetable/tv-collapsable.gif", shutImg: "{$theme}images/treetable/tv-expandable.gif", leafImg: "{$theme}images/treetable/tv-item.gif", lastOpenImg: "{$theme}images/treetable/tv-collapsable-last.gif", lastShutImg: "{$theme}images/treetable/tv-expandable-last.gif", lastLeafImg: "{$theme}images/treetable/tv-item-last.gif", vertLineImg: "{$theme}images/treetable/vertline.gif", blankImg: "{$theme}images/treetable/blank.gif", collapse: collapse, column: 0{literal}}{/literal};
    $("#treetable").jqTreeTable(map, options);
{literal}    
});
</script>
{/literal}

{literal}
<script type="text/javascript">

$(document).ready(function(){
	$("#sTree").treeview({
		persist: "cookie",
		collapsed: true/*,
		unique: true*/
	});
});
</script>
 
{/literal}